/*
@auther fenglei
*/
package xconv

import (
	"github.com/duke-git/lancet/v2/convertor"
	"github.com/duke-git/lancet/v2/strutil"
)

func ToInt32(any interface{}) int32 {
	if any == nil {
		return 0
	}
	if v, ok := any.(int32); ok {
		return v
	}
	v, err := convertor.ToInt(any)
	if err != nil {
		return 0
	}
	return int32(v)
}
func ToInt64(any interface{}) int64 {
	v, err := convertor.ToInt(any)
	if err != nil {
		return 0
	}
	return v
}
func ToInt64s(any string, sep string) []int64 {
	var a []int64
	array := strutil.SplitEx(any, sep, false)
	for _, v := range array {
		a = append(a, ToInt64(v))
	}
	return a
}
func ToInt32s(any string, sep string) []int32 {
	var a []int32
	array := strutil.SplitEx(any, sep, false)
	for _, v := range array {
		a = append(a, ToInt32(v))
	}
	return a
}
func ToStrings(any string, sep string) []string {
	return strutil.SplitEx(any, sep, false)
}
func ToStringSlice(data interface{}) []string {
	// 类型断言
	if strSlice, ok := data.([]string); ok {
		return strSlice
	} else {
		return []string{}
	}
}
